# 第六周作业
# 实现一个 timeit 的装饰器
# timeit 装饰能够计算被装饰函数的运行时间

import datetime, time, functools

def timeit(fn):
    @functools.wraps(fn)     # wrapper = functools.wraps(fn)(wrapper)
    def wrapper(*args, **kwargs):
        start = datetime.datetime.now()
        ret = fn(*args, **kwargs)
        delta = (datetime.datetime.now() - start).total_seconds()
        print("The function {} took {} seconds!".format(fn.__name__, delta))
        return ret
    return wrapper

@timeit     # add = timeit(add)
def add(x, y):
    time.sleep(3)
    return x+y

print(add(1,2))



# 运行结果：
The function add took 3.0 seconds!
3

